﻿using Common.CustomException;
using NUnit.Framework;
using SpecFlowTfsLinker.Entities;
using SpecFlowTfsLinker.Test.Common;
using SpecFlowTfsLinker.Test.Resources;

namespace SpecFlowTfsLinker.Test.Builder
{
    [TestFixture]
    public class StatementBuilderTest : TestInitialization
    {
        [Test]
        public void CanFailWhenICreateNullOrEmptyGiven()
        {
            Assert.Throws(
                Is.TypeOf(typeof (StatementException)).And.Message.EqualTo(
                    Error.BadStatementFormat(StatementType.Given.ToString())), () => Statement.Given(null));
            Assert.Throws(
                Is.TypeOf(typeof (StatementException)).And.Message.EqualTo(
                    Error.BadStatementFormat(StatementType.Given.ToString())), () => Statement.Given(string.Empty));
        }

        [Test]
        public void CanFailWhenICreateNullOrEmptyThen()
        {
            Assert.Throws(
                Is.TypeOf(typeof (StatementException)).And.Message.EqualTo(
                    Error.BadStatementFormat(StatementType.Then.ToString())), () => Statement.Then(null));
            Assert.Throws(
                Is.TypeOf(typeof (StatementException)).And.Message.EqualTo(
                    Error.BadStatementFormat(StatementType.Then.ToString())), () => Statement.Then(string.Empty));
        }

        [Test]
        public void CanFailWhenICreateNullOrEmptyWhen()
        {
            Assert.Throws(
                Is.TypeOf(typeof (StatementException)).And.Message.EqualTo(
                    Error.BadStatementFormat(StatementType.When.ToString())), () => Statement.When(null));
            Assert.Throws(
                Is.TypeOf(typeof (StatementException)).And.Message.EqualTo(
                    Error.BadStatementFormat(StatementType.When.ToString())), () => Statement.When(string.Empty));
        }

        [Test]
        public void CanSuppressAndWordInStatement()
        {
            var givenAnd = Statement.Given(TestCaseResources.GutterGame.And.BaseStatement);
            var whenAnd = Statement.When(TestCaseResources.GutterGame.And.BaseStatement);
            var thenAnd = Statement.Then(TestCaseResources.GutterGame.And.BaseStatement);

            Assert.That(TestCaseResources.GutterGame.And.FinalMethodStatement, Is.EqualTo(givenAnd.Value));
            Assert.That(TestCaseResources.GutterGame.And.FinalMethodStatement, Is.EqualTo(whenAnd.Value));
            Assert.That(TestCaseResources.GutterGame.And.FinalMethodStatement, Is.EqualTo(thenAnd.Value));
        }

        [Test]
        public void CanSuppressGivenWordInStatement()
        {
            var given = Statement.Given(TestCaseResources.GutterGame.Given.BaseStatement);
            Assert.That(TestCaseResources.GutterGame.Given.FinalMethodStatement, Is.EqualTo(given.Value));
        }

        [Test]
        public void CanSuppressThenWordInStatement()
        {
            var then = Statement.Then(TestCaseResources.GutterGame.Then.BaseStatement);
            Assert.That(TestCaseResources.GutterGame.Then.FinalMethodStatement, Is.EqualTo(then.Value));
        }

        [Test]
        public void CanSuppressWhenWordInStatement()
        {
            var when = Statement.When(TestCaseResources.GutterGame.When.BaseStatement);
            Assert.That(TestCaseResources.GutterGame.When.FinalMethodStatement, Is.EqualTo(when.Value));
        }
    }
}